﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebEntities;
using com.subb.WebInfo;
using com.subb.ProductInfo;

namespace WebUI.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.ActMenu = "home";
            WI_NewsDAL ndal = new WI_NewsDAL();
            //获取前10条公司新闻
            int cataId = Extensions.CommonFn.GetContentID("NewsInfoCataId");
            List<WI_News> newsList = ndal.GetAllNews(cataId, 0, 10);
            ViewBag.NewsList1 = newsList;
            //获取前10条行业资讯
            cataId = Extensions.CommonFn.GetContentID("IndustryCataId");
            List<WI_News> newsList2 = ndal.GetAllNews(cataId, 0, 10);
            ViewBag.NewsList2 = newsList2;

            //获取首页推荐产品
            PP_RecomProductDAL rdal = new PP_RecomProductDAL();
            int ttlCount;
            List<PP_RecommendProduct> rprodList = rdal.GetAllRecomProduct(0, 18, out ttlCount, "CN");
            ViewBag.RecomProductList = rprodList;
            //List<PP_RecommendProduct> prodList1 = rprodList.Where(c => c.IndexArea == "indexarea1").Take(6).ToList();
            //List<PP_RecommendProduct> prodList2 = rprodList.Where(c => c.IndexArea == "indexarea2").Take(6).ToList();
            //ViewBag.RecomProductList1 = prodList1;
            //ViewBag.RecomProductList2 = prodList2;

            //获取首页滚动图片
            WI_IndexAdImgDAL mdal = new WI_IndexAdImgDAL();
            List<WI_IndexADImg> imgList = mdal.GetAllADImages();
            ViewBag.ADImgList = imgList;
            
            return View();
        }

        public ActionResult SiteMap()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Search(string seakey, string seatype)
        {
            //string encSearch = HttpUtility.UrlEncode(seakey.Trim());
            if (seatype.ToLower() == "prods")
            {
                return RedirectToAction("SearchProduct", "products", new { seakey = seakey });
            }
            else
            {
                return RedirectToAction("SearchNews", "newsinfo", new { seakey = seakey });
            }
        }
    }
}
